{include file="public/header" /}
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" enctype="multipart/form-data" id="form-member-add">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>键：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="请输入key" value="{$data.key|default=''}" name="key" datatype="*" nullmsg="key不能为空">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>值：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input name="name" cols="" rows="" class="input-text" placeholder="value不能为空" value="{$data.name|default=''}"/>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>说明：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input name="desc" cols="" rows="" class="input-text" placeholder="说明不能为空" value="{$data.desc|default=''}"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width: 200px;">
                <select name="type" class="select">
                    <option value="">----</option>
                    {foreach $types as $v}
                        <option value="{$v.code}" {if isset($v['code']) && $v['code'] == $data['type']}selected{/if} >{$v.name}</option>
                    {/foreach}
                </select>
            </span>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

{include file="public/footer" /}
<script type="text/javascript">
    $(function(){

        $("#form-member-add").validate({
            rules:{
                key:{
                    required:true,
                    minlength:2,
                    maxlength:150
                },
                name:{
                    required:true,
                    minlength:1,
                    maxlength:150
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    success:function(data){
                        console.log(data);
                        if(data.status == 0){
                            layer.msg("操作成功",{icon:1,time:1000,shade: [0.3, '#000']},function(){
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        }else{
                            layer.msg(data.info,{icon:2,time:1000,shade: [0.3, '#000']});
                        }
                    },
                    error:function(error){
                        layer.msg('系统发生了错误',{icon:2,time:3000,shade: [0.5, '#FF0000']});
                    }
                });
            }
        });
    });
</script> 
